import { type Ref, } from "vue";
import Api from "../../components/tools/api";
import { DispatchResult } from "../../tools";

export const findScripts = async (scripts: Ref, type?: number) => {
  try {
    const result = await Api.send(`/script/findAll`, { type });
    DispatchResult(result, {
      onSuccess: (data: any) => {
        scripts.value = data;
        console.log("scripts", scripts.value)
      },
    });
  } catch (error) {
    console.log(error);
  }
}

export const findImages = async (images: Ref, type?: number) => {
  try {
    const result = await Api.send(`/material/findAll`, { type });
    DispatchResult(result, {
      onSuccess: (data: any) => {
        images.value = data;
        console.log("images", images.value)
      },
    });
  } catch (error) {
    console.log(error);
  }
}

export const findSkills = async (skills: Ref, type?: number) => {
  try {
    const result = await Api.send(`/skill/findAll`, { type })
    DispatchResult(result, {
      onSuccess: (data: any) => {
        skills.value = data
        console.log('skills', skills.value)
      }
    })
  } catch (error) {
    console.log(error)
  }
}

export const findItems = async (items: Ref, type?: number) => {
  try {
    const result = await Api.send(`/item/findAll`, { type })
    DispatchResult(result, {
      onSuccess: (data: any) => {
        items.value = data
        console.log('items', items.value)
      }
    })
  } catch (error) {
    console.log(error)
  }
}

export const findMissions = async (missions: Ref, type?: number) => {
  try {
    const result = await Api.send(`/mission/findAll`, { type })
    DispatchResult(result, {
      onSuccess: (data: any) => {
        missions.value = data
        console.log('missions', missions.value)
      }
    })
  } catch (error) {
    console.log(error)
  }
}